<?php 
header("content-type:text/html;charset=utf8");
//接值
$city=$_POST["city"];
//开启缓存
$redis=new redis();
//连接
$redis->connect("127.0.0.1","6379");
//设置一个citys
$citys=$redis->get("citys$city");
if(empty($citys))
{
	$url="http://api.k780.com:88/?app=weather.future&weaid=$city&&appkey=10003&sign=b59bc3ef6191eb9f747dd4e83c99f2a4&format=json";
	// print_r($url);die;
	//采集
	$citys=file_get_contents($url);
	$redis->set("citys$city",$citys);
}
   $res=json_decode($citys,true);
   // print_r($res);die;
   //连选库
	$db=new PDO("mysql:host=127.0.0.1;dbname=bj07c;charset=utf8","root","root");
	//循环读取数据
	foreach ($res['result'] as $key => $value) {
		// print_r($value);
	   $citynm=$value["citynm"];	
	   $days=$value["days"];	
	   $temperature=$value["temperature"];	
	   $sql="insert into tq value(null,'$citynm','$days','$temperature')";
		// print_r($sql);die;
		$info=$db->exec($sql); 
	}
	
   echo $citys;
 ?>